/// branchId : 7636
/// breakfastTimeRange : "undefined-undefined"
/// content : null
/// createdBy : "8368"
/// createdDate : "2023-03-09 10:53:13"
/// dinnerTimeRange : "undefined-undefined"
/// fitPeople : null
/// goodsInfoList : [{"attachIds":"","branchId":7636,"category":null,"createdBy":"8368","createdDate":"2023-03-09 10:53:13","goodsId":941,"goodsName":"番茄炒蛋","id":63,"isDel":0,"isPackage":0,"isWeek":0,"mealSection":null,"menuId":63,"orderType":null,"originalPrice":8,"packFee":null,"price":8,"remark":null,"saasId":1000,"selectNumber":null,"specs":"","status":0,"supplyDate":null,"tenantId":1000,"timeSection":null,"typeName":"热菜","unit":"份","updatedBy":"8368","updatedDate":"2023-03-10 17:16:31","weekDay":null}]
/// id : 63
/// info : null
/// isDel : 0
/// isWeek : 0
/// lunthTimeRange : "undefined-undefined"
/// menuEndDate : null
/// menuJson : null
/// menuStartDate : "2023-03-09 00:00:00"
/// name : "零点菜单"
/// orderModelId : 5
/// orderModelName : "零点点餐"
/// orderType : null
/// packageLabel : null
/// packageLabelName : null
/// remark : null
/// saasId : 1000
/// siteIdList : null
/// siteList : null
/// siteNames : null
/// status : 0
/// tenantId : 1000
/// toPeople : null
/// updatedBy : "8368"
/// updatedDate : "2023-03-10 17:16:31"
/// weekMenuModel : null

class SingleMenuData {
  SingleMenuData({
    this.branchId,
    this.breakfastTimeRange,
    this.content,
    this.createdBy,
    this.createdDate,
    this.dinnerTimeRange,
    this.fitPeople,
    this.goodsInfoList,
    this.id,
    this.info,
    this.isDel,
    this.isWeek,
    this.lunthTimeRange,
    this.menuEndDate,
    this.menuJson,
    this.menuStartDate,
    this.name,
    this.orderModelId,
    this.orderModelName,
    this.orderType,
    this.packageLabel,
    this.packageLabelName,
    this.remark,
    this.saasId,
    this.siteIdList,
    this.siteList,
    this.siteNames,
    this.status,
    this.tenantId,
    this.toPeople,
    this.updatedBy,
    this.updatedDate,
    this.weekMenuModel,
  });

  int get selectCount {
    var count = 0;
    for (var item in goodsInfoList ?? <SingleGoodsInfoList>[]) {
      count += item.number;
    }
    return count;
  }

  double get selectPrice {
    var price = 0.0;
    for (var item in goodsInfoList ?? <SingleGoodsInfoList>[]) {
      price += item.number * (item.price??0);
    }
    return price;
  }

  List<SingleGoodsInfoList> get selectFoodList{
    var list = <SingleGoodsInfoList>[];
    for (var item in goodsInfoList ?? <SingleGoodsInfoList>[]) {
       if(item.number>0){
         list.add(item);
       }
    }
    return list;
  }

  SingleMenuData.fromJson(dynamic json) {
    branchId = json['branchId'];
    breakfastTimeRange = json['breakfastTimeRange'];
    content = json['content'];
    createdBy = json['createdBy'];
    createdDate = json['createdDate'];
    dinnerTimeRange = json['dinnerTimeRange'];
    fitPeople = json['fitPeople'];
    if (json['goodsInfoList'] != null) {
      goodsInfoList = [];
      json['goodsInfoList'].forEach((v) {
        goodsInfoList?.add(SingleGoodsInfoList.fromJson(v));
      });
    }
    id = json['id'];
    info = json['info'];
    isDel = json['isDel'];
    isWeek = json['isWeek'];
    lunthTimeRange = json['lunthTimeRange'];
    menuEndDate = json['menuEndDate'];
    menuJson = json['menuJson'];
    menuStartDate = json['menuStartDate'];
    name = json['name'];
    orderModelId = json['orderModelId'];
    orderModelName = json['orderModelName'];
    orderType = json['orderType'];
    packageLabel = json['packageLabel'];
    packageLabelName = json['packageLabelName'];
    remark = json['remark'];
    saasId = json['saasId'];
    siteIdList = json['siteIdList'];
    siteList = json['siteList'];
    siteNames = json['siteNames'];
    status = json['status'];
    tenantId = json['tenantId'];
    toPeople = json['toPeople'];
    updatedBy = json['updatedBy'];
    updatedDate = json['updatedDate'];
    weekMenuModel = json['weekMenuModel'];
  }

  num? branchId;
  String? breakfastTimeRange;
  dynamic content;
  String? createdBy;
  String? createdDate;
  String? dinnerTimeRange;
  dynamic fitPeople;
  List<SingleGoodsInfoList>? goodsInfoList;
  num? id;
  dynamic info;
  num? isDel;
  num? isWeek;
  String? lunthTimeRange;
  dynamic menuEndDate;
  dynamic menuJson;
  String? menuStartDate;
  String? name;
  num? orderModelId;
  String? orderModelName;
  dynamic orderType;
  dynamic packageLabel;
  dynamic packageLabelName;
  dynamic remark;
  num? saasId;
  dynamic siteIdList;
  dynamic siteList;
  dynamic siteNames;
  num? status;
  num? tenantId;
  dynamic toPeople;
  String? updatedBy;
  String? updatedDate;
  dynamic weekMenuModel;

  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    map['branchId'] = branchId;
    map['breakfastTimeRange'] = breakfastTimeRange;
    map['content'] = content;
    map['createdBy'] = createdBy;
    map['createdDate'] = createdDate;
    map['dinnerTimeRange'] = dinnerTimeRange;
    map['fitPeople'] = fitPeople;
    if (goodsInfoList != null) {
      map['goodsInfoList'] = goodsInfoList?.map((v) => v.toJson()).toList();
    }
    map['id'] = id;
    map['info'] = info;
    map['isDel'] = isDel;
    map['isWeek'] = isWeek;
    map['lunthTimeRange'] = lunthTimeRange;
    map['menuEndDate'] = menuEndDate;
    map['menuJson'] = menuJson;
    map['menuStartDate'] = menuStartDate;
    map['name'] = name;
    map['orderModelId'] = orderModelId;
    map['orderModelName'] = orderModelName;
    map['orderType'] = orderType;
    map['packageLabel'] = packageLabel;
    map['packageLabelName'] = packageLabelName;
    map['remark'] = remark;
    map['saasId'] = saasId;
    map['siteIdList'] = siteIdList;
    map['siteList'] = siteList;
    map['siteNames'] = siteNames;
    map['status'] = status;
    map['tenantId'] = tenantId;
    map['toPeople'] = toPeople;
    map['updatedBy'] = updatedBy;
    map['updatedDate'] = updatedDate;
    map['weekMenuModel'] = weekMenuModel;
    return map;
  }
}

class SingleGoodsInfoList {
  SingleGoodsInfoList({
    this.attachIds,
    this.branchId,
    this.category,
    this.createdBy,
    this.createdDate,
    this.goodsId,
    this.goodsName,
    this.id,
    this.isDel,
    this.isPackage,
    this.isWeek,
    this.mealSection,
    this.menuId,
    this.orderType,
    this.originalPrice,
    this.packFee,
    this.price,
    this.remark,
    this.saasId,
    this.selectNumber,
    this.specs,
    this.status,
    this.supplyDate,
    this.tenantId,
    this.timeSection,
    this.typeName,
    this.unit,
    this.updatedBy,
    this.updatedDate,
    this.weekDay,
  });

  var number = 0;

  SingleGoodsInfoList.fromJson(dynamic json) {
    attachIds = json['attachIds'];
    branchId = json['branchId'];
    category = json['category'];
    createdBy = json['createdBy'];
    createdDate = json['createdDate'];
    goodsId = json['goodsId'];
    goodsName = json['goodsName'];
    id = json['id'];
    isDel = json['isDel'];
    isPackage = json['isPackage'];
    isWeek = json['isWeek'];
    mealSection = json['mealSection'];
    menuId = json['menuId'];
    orderType = json['orderType'];
    originalPrice = json['originalPrice'];
    packFee = json['packFee'];
    price = json['price'];
    remark = json['remark'];
    saasId = json['saasId'];
    selectNumber = json['selectNumber'];
    specs = json['specs'];
    status = json['status'];
    supplyDate = json['supplyDate'];
    tenantId = json['tenantId'];
    timeSection = json['timeSection'];
    typeName = json['typeName'];
    unit = json['unit'];
    updatedBy = json['updatedBy'];
    updatedDate = json['updatedDate'];
    weekDay = json['weekDay'];
  }

  String? attachIds;
  num? branchId;
  dynamic category;
  String? createdBy;
  String? createdDate;
  num? goodsId;
  String? goodsName;
  num? id;
  num? isDel;
  num? isPackage;
  num? isWeek;
  dynamic mealSection;
  num? menuId;
  dynamic orderType;
  num? originalPrice;
  dynamic packFee;
  num? price;
  dynamic remark;
  num? saasId;
  dynamic selectNumber;
  String? specs;
  num? status;
  dynamic supplyDate;
  num? tenantId;
  dynamic timeSection;
  String? typeName;
  String? unit;
  String? updatedBy;
  String? updatedDate;
  dynamic weekDay;

  SingleGoodsInfoList copyWith({
    String? attachIds,
    num? branchId,
    dynamic category,
    String? createdBy,
    String? createdDate,
    num? goodsId,
    String? goodsName,
    num? id,
    num? isDel,
    num? isPackage,
    num? isWeek,
    dynamic mealSection,
    num? menuId,
    dynamic orderType,
    num? originalPrice,
    dynamic packFee,
    num? price,
    dynamic remark,
    num? saasId,
    dynamic selectNumber,
    String? specs,
    num? status,
    dynamic supplyDate,
    num? tenantId,
    dynamic timeSection,
    String? typeName,
    String? unit,
    String? updatedBy,
    String? updatedDate,
    dynamic weekDay,
  }) =>
      SingleGoodsInfoList(
        attachIds: attachIds ?? this.attachIds,
        branchId: branchId ?? this.branchId,
        category: category ?? this.category,
        createdBy: createdBy ?? this.createdBy,
        createdDate: createdDate ?? this.createdDate,
        goodsId: goodsId ?? this.goodsId,
        goodsName: goodsName ?? this.goodsName,
        id: id ?? this.id,
        isDel: isDel ?? this.isDel,
        isPackage: isPackage ?? this.isPackage,
        isWeek: isWeek ?? this.isWeek,
        mealSection: mealSection ?? this.mealSection,
        menuId: menuId ?? this.menuId,
        orderType: orderType ?? this.orderType,
        originalPrice: originalPrice ?? this.originalPrice,
        packFee: packFee ?? this.packFee,
        price: price ?? this.price,
        remark: remark ?? this.remark,
        saasId: saasId ?? this.saasId,
        selectNumber: selectNumber ?? this.selectNumber,
        specs: specs ?? this.specs,
        status: status ?? this.status,
        supplyDate: supplyDate ?? this.supplyDate,
        tenantId: tenantId ?? this.tenantId,
        timeSection: timeSection ?? this.timeSection,
        typeName: typeName ?? this.typeName,
        unit: unit ?? this.unit,
        updatedBy: updatedBy ?? this.updatedBy,
        updatedDate: updatedDate ?? this.updatedDate,
        weekDay: weekDay ?? this.weekDay,
      );

  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    map['attachIds'] = attachIds;
    map['branchId'] = branchId;
    map['category'] = category;
    map['createdBy'] = createdBy;
    map['createdDate'] = createdDate;
    map['goodsId'] = goodsId;
    map['goodsName'] = goodsName;
    map['id'] = id;
    map['isDel'] = isDel;
    map['isPackage'] = isPackage;
    map['isWeek'] = isWeek;
    map['mealSection'] = mealSection;
    map['menuId'] = menuId;
    map['orderType'] = orderType;
    map['originalPrice'] = originalPrice;
    map['packFee'] = packFee;
    map['price'] = price;
    map['remark'] = remark;
    map['saasId'] = saasId;
    map['selectNumber'] = selectNumber;
    map['specs'] = specs;
    map['status'] = status;
    map['supplyDate'] = supplyDate;
    map['tenantId'] = tenantId;
    map['timeSection'] = timeSection;
    map['typeName'] = typeName;
    map['unit'] = unit;
    map['updatedBy'] = updatedBy;
    map['updatedDate'] = updatedDate;
    map['weekDay'] = weekDay;
    return map;
  }
}

class SingleTypeData {
  String typeName;
  List<SingleGoodsInfoList> foodList = [];

  SingleTypeData(this.typeName);

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      other is SingleTypeData &&
          runtimeType == other.runtimeType &&
          typeName == other.typeName;

  @override
  int get hashCode => typeName.hashCode;
}

extension TypeChangeEx on List<SingleGoodsInfoList> {
  List<SingleTypeData> toTypeData() {
    var list = <SingleTypeData>[];
    for (var food in this) {
      var data = SingleTypeData(food.typeName??"");
      if (!list.contains(data)) {
        data.foodList.add(food);
        list.add(data);
      } else {
        var index = list.indexOf(data);
        list[index].foodList.add(food);
      }
    }
    return list;
  }
}
